// bwh record page
// ============

define(['zepto', 'sui', 'utils', 'wxshare'], 
function($, sui, utils, wxshare) {
  return {
    init: function(data) {
      this.initSubmit(data.courseRoundId);
    },
    
    initSubmit: function(courseRoundId) {
        var that = this;
        $(".button").on("click", function(e){
          
            e.preventDefault();
            
            var bust = $("input[name='bust']").val();
            if(!bust) {
                return  $.toast('请输入胸围');
            } else if(bust <= 0) {
            	return  $.toast('请输入格式正确的胸围');
            }
            
            var waist = $("input[name='waist']").val();
            if(!waist) {
                return  $.toast('请输入腰围');
            } else if(waist <= 0) {
            	return  $.toast('请输入格式正确的腰围');
            }
            
            var hips = $("input[name='hips']").val();
            if(!hips) {
                return  $.toast('请输入臀围');
            } else if(hips <= 0) {
            	return  $.toast('请输入格式正确的臀围');
            }
            
            var weight = $("input[name='weight']").val();
            if(!weight) {
                return  $.toast('请输入体重');
            } else if(weight <= 0) {
            	return  $.toast('请输入格式正确的体重');
            }
            
            $.showPreloader('正在提交')
            var $form = $("form");
            console.log($form.serializeArray())
            $.post($($form).attr("action"), $form.serializeArray()).done(
              function(response) {
                $.hidePreloader()
                utils.processResult(response, function(result) {
                  $.toast(result.message || "添加成功")
                  setTimeout(function() {
                    window.location.href = __CTX__.root + "/profile/courses/" + courseRoundId + "/bmr-records";
                  }, 1000)
                }, function(result) {
                  $.toast(result.message || '添加失败')
               })
            })
          
        });
    }
    
  }
})